// JavaScript Document

//
var pnavspeed = 500;
//
var pnavtype = 'home';
var pnavsize = {width: 3322, height: 2044, pw: 400, ph: 400};
var pnavps = [];
pnavps['about'] = {x: 50, y: 18};
pnavps['contact'] = {x: 1133, y: 18};
pnavps['audition'] = {x: 2313, y: 19};

pnavps['news'] = {x: 185, y: 680};
pnavps['home'] = {x: 1195, y: 680};
pnavps['staff'] = {x: 2205, y: 680, subs: 1};

pnavps['support'] = {x: 40, y: 1375};
pnavps['tour'] = {x: 1047, y: 1375};
pnavps['photo'] = {x: 2095, y: 1375};

//
pnavps['staff_maestro_rocky_lee'] = {x: 2205, y: 680, parent: 'staff', path: '', imgs: []};
pnavps['staff_maestro_dan_robbins'] = {x: 2205, y: 680, parent: 'staff', path: 'staff/maestro_dan_robbins/', imgs: []};
pnavps['staff_maestro_mark_alpizar'] = {x: 2205, y: 680, parent: 'staff', path: 'staff/maestro_mark_alpizar/', imgs: []};

//
function pnav_subs(type){
	var subs = [];
	for(var pt in pnavps){
		if( pnavps[pt].parent != null && type == pnavps[pt].parent ){
			subs.push(pt);
		}
	}
	return subs;
}

//to
function pnavtopt(type,obj){
	$('#topmenu li').each(function(i){
						$(this).removeClass("cc");
								   });
	if( obj && obj.parentNode ){
		obj.parentNode.className += " cc";
	}
	document.location.hash = type;
	var ptp = null;
	for(var pt in pnavps){
		if( type == pt ){
			ptp = pt;
			break;
		}
	}
	if( ptp != null ){
		$('#mcls').animate({scrollLeft: pnavps[pt].x, scrollTop: pnavps[pt].y}, 
			pnavspeed, 'swing', //swing/linear, 
			function(){
				// Animation complete.
				});
	}
}

//image
function pnavtoptx(type,obj){
	$('#topmenu li').each(function(i){
						$(this).removeClass("cc");
								   });
	if( obj && obj.parentNode ){
		obj.parentNode.className += " cc";
		obj.parentNode.parentNode.parentNode.className += " cc";
	}
	document.location.hash = type;
	var ptp = null;
	var issub = false;
	for(var pt in pnavps){
		if( type == pt ){
			ptp = pt;
			if( pnavps[pt].parent != null ){
				issub = true;	
			}
			break;
		}
	}
	if( ptp != null ){
		if( issub == true ){
			$('#mcds img').each(function(i){
							if( this.getAttribute(type) != null ){
								this.setAttribute("src", this.getAttribute(type));
							}
								});
		}
		
		$('#mcls').animate({scrollLeft: pnavps[ptp].x, scrollTop: pnavps[ptp].y}, 
			pnavspeed, 'swing', //swing/linear, 
			function(){
				// Animation complete.
				});
	}
}

//text
//staff
function pnavtoptd(type,parent,obj){
	$('#topmenu li').each(function(i){
						$(this).removeClass("cc");
								   });
	if( obj && obj.parentNode ){
		obj.parentNode.className += " cc";
		obj.parentNode.parentNode.parentNode.className += " cc";
	}
	document.location.hash = type;
	var ptp = null;
	for(var pt in pnavps){
		if( parent == pt ){
			ptp = pt;
		}
	}
	if( ptp != null ){
		if($E(type)){
			var a = $E(type).parentNode.getElementsByTagName("DIV");
			for(var i=0; i<a.length; i++){
				if(a[i].id && a[i].id.indexOf(parent) > -1){
					dhide(a[i]);	
				}
			}
			dshow($E(type));
		}
		$('#mcls').animate({scrollLeft: pnavps[ptp].x, scrollTop: pnavps[ptp].y}, 
			pnavspeed, 'swing', //swing/linear, 
			function(){
				// Animation complete.
				});
	}
}

//photo
function pnavtoptdp(type,parent,obj,pid){
	pnavtoptd(type,parent,obj);
	pimg_ssd(pid);
}

//
$(document).ready(function(){
	if( document.location.hash ){
		pnavtype = document.location.hash.substring(1);
	}
	//
	if(jQuery.browser.msie){
		pnavspeed = 320;
	}
	//
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6){
		$('#topmenu li').hover(
					function(){
						//alert($('ul', this).offset().left+","+$(this).offset().left);
						$('ul', this).css('display', 'block').css('position', 'absolute')
							.css('left', $(this).offset().left)
							.css('top', 27)
							.css('zIndex', 100);
					},
					function(){ 
						$('ul', this).css('display', 'none');
					});
	}
	/*
	$('#topmenu li').hover(
				function(){ $('ul', this).css('display', 'block'); },
				function(){ $('ul', this).css('display', 'none'); });
	*/
	//
	var ptp = null;
	var pnavxc = Math.ceil(pnavsize.width/pnavsize.pw);
	var pnavyc = Math.ceil(pnavsize.height/pnavsize.ph);
	var ptpxc = 0;
	var ptpyc = 0;
	var ptpwc = 2;
	var ptphc = 2;
	for(var pt in pnavps){
		if( pnavtype == pt ){
			ptp = pnavps[pt];
			break;
		}
	}
	if( ptp == null ){
		pnavtype = "home";
		ptp = pnavps[pnavtype];
	}
	ptpxc = Math.floor(ptp.x/pnavsize.pw);
	ptpyc = Math.floor(ptp.y/pnavsize.ph);
	//
	$('#mcds img').each(function(i){
					var yc = Math.ceil((i+1)/pnavxc)-1;
					var xc = i-Math.floor((i+1)/pnavxc) * pnavxc;
					if( xc >= ptpxc && xc - ptpxc <= ptpwc && yc >= ptpyc && yc - ptpyc <= ptphc ){
						this.setAttribute("src", this.getAttribute("dsrc"));
					} else {
						//this.setAttribute("src", this.getAttribute("dsrc"));
					}
						});
	//
	pnavtopt(pnavtype);
	//
	$('#mcds img').each(function(i){
					var yc = Math.ceil((i+1)/pnavxc)-1;
					var xc = i-Math.floor((i+1)/pnavxc) * pnavxc;
					if( xc >= ptpxc && xc - ptpxc <= ptpwc && yc >= ptpyc && yc - ptpyc <= ptphc ){
						//this.setAttribute("src", this.getAttribute("dsrc"));
					} else {
						this.setAttribute("src", this.getAttribute("dsrc"));
					}
						});
	//
	/*
	//preload
	//staff
	var ptp = pnavps['staff'];
	var ptpsubs = pnav_subs('staff');
	ptpxc = Math.floor(ptp.x/pnavsize.pw);
	ptpyc = Math.floor(ptp.y/pnavsize.ph);
	//
	$('#mcds img').each(function(i){
					var yc = Math.ceil((i+1)/pnavxc)-1;
					var xc = i-Math.floor((i+1)/pnavxc) * pnavxc;
					if( xc >= ptpxc && xc - ptpxc <= ptpwc && yc >= ptpyc && yc - ptpyc <= ptphc ){
						var dsrc = this.getAttribute("dsrc");
						for(var j=0; j<ptpsubs.length; j++){
							var ptps = pnavps[ptpsubs[j]];
							var src = dsrc.substring(0, dsrc.lastIndexOf('/')+1)+ptps.path+dsrc.substring(dsrc.lastIndexOf('/')+1);
							this.setAttribute(ptpsubs[j], src);
							//var img = new Image();
							//img.src = src;
							//ptps.imgs.push(img);
						}
					}
						});
	*/
	//
});


//////////////////////////////////////////////////////////////////////////////
function pm_left(){
	$('#mcls').scrollLeft($('#mcls').scrollLeft()-500);
}
function pm_right(){
	$('#mcls').scrollLeft($('#mcls').scrollLeft()+500);
}
function pm_top(){
	$('#mcls').scrollTop($('#mcls').scrollTop()-500);
}
function pm_bottom(){
	$('#mcls').scrollTop($('#mcls').scrollTop()+500);
}
//
function pw_about(){

}
function pw_support(){
	alert($('#pw_support').css('top'));
}
function pw_tour(){

}
function pw_photo(){
	alert($('#pw_photo').css('top'));
}
									  